//
//  PywGetOrderInfoApi.m
//  PywSdk
//
//  Created by Jade on 16/11/19.
//  Copyright © 2016年 Jade. All rights reserved.
//

#import "PywGetOrderInfoApi.h"
#import "PropertyListReformer.h"
#import "PywMBProgressHUD+Pyw.h"

@interface PywGetOrderInfoApi ()<ETAPIManagerCallBackDelegate>

@end

@implementation PywGetOrderInfoApi
/**
 *  生成订单
 */
- (void)getOrderInfo:(Successd)success
                fail:(Failure)fail
{
    self.successd = success;
    self.failure = fail;
    AIFGetOrderInfoManager *manager = [AIFGetOrderInfoManager manager];
    manager.delegate = self;
    [manager loadData];
}


#pragma mark - ETAPIManagerCallBackDelegate

- (void)managerCallAPIDidSuccess:(ETApiBaseManager *)manager{
    [PywMBProgressHUD hideHUD];
    PropertyListReformer *reformer = [[PropertyListReformer alloc] init];
    NSDictionary *dict = [manager fetchDataWithReformer:reformer];
    
    int resultCode = [[dict objectForKey:@"ack"] intValue];
    switch (resultCode) {
        case 200:
        {
            if (self.successd) {
                self.successd(nil,dict);
            }
        }
            break;
            
        default:
        {
            NSString *msg = [dict objectForKey:@"msg"];
            [PywMBProgressHUD showError:msg];
            if (self.failure) {
                self.failure([self errorWithCode:resultCode]);
            }
        }
            break;
    }
}

- (void)managerCallApiDidFailed:(ETApiBaseManager *)manager
{
    [PywMBProgressHUD hideHUD];
    if (self.failure) {
        self.failure(nil);
    }
}


@end
